#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/epoll.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include"processpool.h"


int main(int argc, char ** argv)
{
	if (argc<=2)
	{
		printf("usage:%s ip port",basename(argv[0]));
		exit(0);
	}


    const char* ip = argv[1];
    int port = atoi( argv[2] );

    int ret = 0;
    int listenfd;
    struct sockaddr_in address;
    bzero( &address, sizeof( address ) );
    address.sin_family = AF_INET;
    inet_pton( AF_INET, ip, &address.sin_addr );
    address.sin_port = htons( port );

    listenfd = socket( PF_INET, SOCK_STREAM, 0 );
    assert( listenfd >= 0 );

    ret = bind( listenfd, ( struct sockaddr* )&address, sizeof( address ) );
    assert( ret != -1 );

    ret = listen( listenfd, 5 );
    assert( ret != -1 );


    processpool * pp=processpool::create(listenfd,8);
    if(pp)
    {
	    pp->run();
	    delete pp;
    }

    close(listenfd);
    return 0;


}
